package com.yxhl.zoume.core.busticket.model;

import com.yxhl.protobuf.ScheduleType;
import com.yxhl.protobuf.YxScheduleRequest;
import com.yxhl.zoume.core.busticket.ui.info.ZMScheduleType;
import com.yxhl.zoume.data.http.model.base.BaseModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Xboy on 16/4/7.
 */
public class TicketsQueryOptions extends BaseModel {

    public static final long serialVersionUID = 41L;

    // 出发城市编码
    private String startCityCode;
    // 出发站名称
    private String startCityName;
    // 出行时间
    private String tripDate;
    // 到达站名称
    private String arrivalCityName;

    private String arrivalCityCode;

    private List<ZMScheduleType> scheduleTypeList;

    public TicketsQueryOptions(String startCityCode, String startCityName, String tripDate, String arrivalCityName, String arrivalCityCode, List<ZMScheduleType> scheduleTypeList) {
        this.startCityCode = startCityCode;
        this.startCityName = startCityName;
        this.tripDate = tripDate;
        this.arrivalCityName = arrivalCityName;
        this.arrivalCityCode = arrivalCityCode;
        this.scheduleTypeList = scheduleTypeList;
    }

    public YxScheduleRequest generateParam() {
        YxScheduleRequest yxScheduleRequest = YxScheduleRequest.newBuilder()
                .setStartCity(this.startCityName)
                .setStartCityCode(this.startCityCode)
                .setEndCity(this.arrivalCityName)
                .setEndCityCode(this.arrivalCityCode)
                .setGmtDepart(this.tripDate)
                .addAllType(getScheduleType(scheduleTypeList))
                .build();

        return yxScheduleRequest;
    }

    public YxScheduleRequest generateParam(String tripDate) {
        YxScheduleRequest yxScheduleRequest = YxScheduleRequest.newBuilder()
                .setStartCity(this.startCityName)
                .setStartCityCode(this.startCityCode)
                .setEndCity(this.arrivalCityName)
                .setEndCityCode(this.arrivalCityCode)
                .setGmtDepart(tripDate)
                .addAllType(getScheduleType(scheduleTypeList))
                .build();

        return yxScheduleRequest;
    }

    public String getStartCityCode() {
        return startCityCode;
    }

    public TicketsQueryOptions setStartCityCode(String startCityCode) {
        this.startCityCode = startCityCode;
        return this;
    }

    public String getStartCityName() {
        return startCityName;
    }

    public TicketsQueryOptions setStartCityName(String startCityName) {
        this.startCityName = startCityName;
        return this;
    }

    public String getTripDate() {
        return tripDate;
    }

    public TicketsQueryOptions setTripDate(String tripDate) {
        this.tripDate = tripDate;
        return this;
    }

    public String getArrivalCityName() {
        return arrivalCityName;
    }

    public TicketsQueryOptions setArrivalCityName(String arrivalCityName) {
        this.arrivalCityName = arrivalCityName;
        return this;
    }

    private List<ScheduleType> getScheduleType(List<ZMScheduleType> zmScheduleTypeList) {
        List<ScheduleType> scheduleTypeList = new ArrayList<>();
        if (zmScheduleTypeList != null) {
            for (ZMScheduleType zmScheduleType : zmScheduleTypeList) {
                ScheduleType scheduleType;
                switch (zmScheduleType) {
                    case V_DIY_BUS:
                        scheduleType = ScheduleType.V_DIY_BUS;
                        break;
                    case V_FT_BUS:
                        scheduleType = ScheduleType.V_FT_BUS;
                        break;
                    case V_XD_BUS:
                        scheduleType = ScheduleType.V_XD_BUS;
                        break;
                    case V_DABA_BUS:
                        scheduleType = ScheduleType.V_DABA_BUS;
                        break;
                    default:
                        scheduleType = null;
                }
                scheduleTypeList.add(scheduleType);
            }
        }
        return scheduleTypeList;
    }

}
